import pygame, sys, math, random
from pygame.locals import *
from bullet import *

# This creates the Player.
# This is only the the moving vehicel on the screen,
# all savegame relevant topics are in a seperate file.

class Player:
     def __init__(self):
          self.life = 100
          self.shield = 25
          self.posx = 400
          self.posy = 300
          self.width = 40
          self.height = 52
          self.maxSpeed = 15
          self.velocity = 2
          self.velw = 0
          self.vela = 0
          self.vels = 0
          self.veld = 0
          self.w = False
          self.a = False
          self.s = False
          self.d = False
          self.preciseMode = False
          self.fireWeapon = False
          self.amountBombs = 3
          self.fireSpeed = 0
          self.weaponCooldown = 0
          self.bulletArray = []
          self.weaponDamage = 50
          self.isInStage = 1
          self.Score = 0
          self.Money = 0

     
     def move(self):
          if self.w and self.posy > 15:
               if self.velw < self.maxSpeed:
                    self.velw += self.velocity                   
          else:
               if self.velw > 0:
                    self.velw -= self.velocity                    
               
          if self.a and self.posx > 15:
               if self.vela < self.maxSpeed:
                    self.vela += self.velocity                   
          else:
               if self.vela > 0:
                    self.vela -= self.velocity                 
               
          if self.s and self.posy < 753 :
               if self.vels < self.maxSpeed:
                    self.vels += self.velocity                    
          else:
               if self.vels > 0:
                    self.vels -= self.velocity                    

          if self.d and self.posx < 1009:
               if self.veld < self.maxSpeed:
                    self.veld += self.velocity 
          else:
               if self.veld > 0:
                    self.veld -= self.velocity
          
          if self.preciseMode:
               devider = 2
          else:
               devider = 1
          
          if self.velw > 0 and self.posy > 15:
                    self.posy -= int(self.velw / devider)
          if self.vela > 0 and self.posx > 15:
                    self.posx -= int(self.vela / devider)
          if self.vels > 0 and self.posy < 753 - self.height:
                    self.posy += int(self.vels / devider)
          if self.veld > 0 and self.posx < 1009 - self.width:
                    self.posx += int(self.veld / devider)
     
     def fire(self):
          if self.fireWeapon and self.weaponCooldown == 0:
               self.weaponCooldown = 5 - self.fireSpeed
               self.bulletArray.append(Bullet(self.posx, self.posy, self.posx, self.posy - 1000))
               
          if self.weaponCooldown > 0:
               self.weaponCooldown -= 1
     
     def reset(self):
          self.posx = 300
          self.posy = 400
          self.bulletArray = []
